home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Asm_course / assembler course / 7.s < prev    next >
Encoding:
Text File  |  1992-04-27  |  4.5 KB  |  115 lines

  1.  
  2. ; have you ever heared of 'libraries' ?  good ! Libraries contain
  3. ; many interesting subroutines that can take a lot of work out of
  4. ; our hands. Amiga has several libraries, one for graphics, one
  5. ; for disk, one for workbench...  The only problem is, that the
  6. ; routines are in most cases very SLOW. That is so because AMiga is
  7. ; a very complex computer, and these routines are written in a way
  8. ; that they keep everything in mind, for example it's possible that
  9. ; 2 programs are using disk, so the routines must count with this
  10. ; possibility. It must for example wait for one routine to be 
  11. ; finished before it can start itself, etc etc...
  12. ; In DEMOS, we ofcourse want to do much things at one time, and 
  13. ; preferably as FAST as posible, (try to put 200 bobs on a screen,
  14. ; you'll know what I mean)  So we will reduce the use of libraries
  15. ; to a MINIMUM !!
  16. ; For some purposes, libraries can be very interesting, though.
  17. ; That's why I'll tell you how to use them...
  18.  
  19. ; Now, first good question: where are these libraries ?
  20. ; The computer knows where they are, but you can only find out by
  21. ; calling a routine called 'openlibrary', which is in a LIBRARY.
  22. ; Well, again, where is this library ??????
  23. ; (seems like we're getting nowhere this way)
  24. ;
  25. ; Here's the solution: the longword stored at address $4 (the 2nd
  26. ; longword of the memory) is the start of the 'EXEC LIBRARY'
  27. ; so with a 'MOVE.L $4,a6'   you can get the starting address of
  28. ; this library.  (not MOVE.L #$4,a6 !!!)
  29. ; In other words, you don't need the routine Openlibrary to open the
  30. ; execlibrary. EXECLIBRARY is therefor the 'most basical' library,
  31. ; with the most important routines.
  32. ; The other libraries must be opened using a function in the execlib
  33. ; The list with available routines is among the copies...
  34.  
  35. ; All routines have a relative address: start location of library +
  36. ; offset. These offsets are for some unknown reason negative,
  37. ; (which means that the 'start location' is in fact the endlocation)
  38. ; Anyway, the function 'OPENLIBRARY' has offset -408, which means
  39. ; that if you move the starting location to A6 (with MOVE.L $4,A6)
  40. ; you must do a 'JSR -408(a6)' to execute the routine OPENLIBRARY.
  41. ; The communication between you and libraries is done through the 
  42. ; REGISTERS (D0-D7 & A0-A6)
  43. ; Each routine has it's own input- and output registers. In the 
  44. ; example of the openlibrary routine, you must tell the routine 
  45. ; which library you wanna open and he will tell you where it is. 
  46. ; If the libary you wanna open is called "graphics.library", the
  47. ; way to open it is :
  48. ;
  49.  
  50. start:    movem.l    d0-d7/a0-a6,-(a7)
  51.  
  52.     move.l    $4,a6        ; get the start of the execlib in a6
  53.  
  54.     clr.l    d0
  55.  
  56.     move.l    #libname,a1    ; a1 is the register through which
  57.                 ; you tell the routine which library
  58.                 ; you wish to open.
  59.                 ; Libname is a label at which we 
  60.                 ; have stored the name. A1 now 
  61.                 ; contains the address of this label
  62.  
  63.     jsr    -408(a6)    ; execute the routine
  64.  
  65.     move.l    d0,gfxbase    ; in D0 is the result of the routine:
  66.                 ; the start of the library. If D0 is
  67.                 ; 0, the library couldn't be opened.
  68.  
  69. *************************
  70.  
  71. ; the library is now opened, in other words, we know where the start
  72. ; location of the GFXlibrary is. If we move this startinglocation to
  73. ; an addresregister, like A6, we can use the routines in the gfx-
  74. ; library, just like we called the 'openlibrary' routine. DOn't forget
  75. ; to tell the computer that you are about to use a routine in the GFX
  76. ; lib,so get this one's starting adress ready in a6:
  77.  
  78. ;    move.l    gfxbase,a6
  79. ;    jsr    -xx(a6)
  80.  
  81. ; At the end of the program, we have to close the opened libraries
  82. ; again (except the execlib) The 'CloseLibrary' routine is at offset
  83. ; -414 from the EXEClibrary.
  84. ; Now we must put the starting location of the previously opened
  85. ; library in A0 to tell the routine which library to close. In our 
  86. ; example, we have put this value in 'gfxbase':
  87.  
  88.     move.l    gfxbase,a1    ; move CONTENTS of gfxbase to a1
  89.                 ; this is the start of the library,
  90.                 ; the one we saved earlier.
  91.  
  92.     move.l    $4,a6        ; we use the EXEC lib !!!
  93.     jsr    -414(a6)    ; the closelib-routine
  94.  
  95.     movem.l    (a7)+,d0-d7/a0-a6
  96.  
  97.     rts            ; exit this program
  98.  
  99. *************************
  100.  
  101.  
  102. gfxbase:    dc.l    0    ; we reserve 1 longword to store
  103.                 ; the starting location of the 
  104.                 ; graphicslibrary. after execution of
  105.                 ; the source, type '@hgfxbase'. The first
  106.                 ; 4 bytes that will be displayed, are
  107.                 ; the contents of this longword.
  108.  
  109. libname:    dc.b    "graphics.library",0
  110.         even
  111.                 ; this is the name of the library.
  112.                 ; The last byte is 0 as 'end-of-
  113.                 ; string' marker.
  114.  
  115.